///////////////////////////////////////////////////////////////////////////////
//
//  ExtendedPlayer
//
//  This extends the base player class, you may override the base player
//  member functions or add additional player functionality here. 
//
///////////////////////////////////////////////////////////////////////////////
Type.registerNamespace('ExtendedPlayer');

ExtendedPlayer.Player = function(domElement) {
    ExtendedPlayer.Player.initializeBase(this, [domElement]); 
    this._videoThumbnail = "";  
    this._currentStateChangedToken = null;
 
}
ExtendedPlayer.Player.prototype =  {
    _tsChanged: function() {
        if (this._dragTime._isDragging) return;
        this._oldtsChanged();
    },
    _thumbUp: function() {
        if (!this._dragTime._enableSeeking) return false;
        return this._oldtsChanged();
    },
    xamlInitialize: function() {    
        ExtendedPlayer.Player.callBaseMethod(this, 'xamlInitialize');
        var _videoElement = this.get_mediaElement();

        this._oldtsChanged = this._dragTime._changedHandler;
        this._dragTime._changedHandler = Function.createDelegate(this, this._tsChanged);
        this._dragTime._thumb.bindEvent("mouseLeftButtonUp", null, this._thumbUp, this); 
        this.get_element().content.findName("VideoThumbnail").Source = mediaImage; 
        this._stateChangedEventDelegate = Function.createDelegate(this, this.stateChangedEvent);
        this._currentStateChangedToken = _videoElement.addEventListener("currentStateChanged", this._stateChangedEventDelegate);
    },
    
    stateChangedEvent: function(sender, args) {
        var mediaElement = this.get_mediaElement();
        if(mediaElement == null)
            return;
        var hasVideo = (this.get_mediaElement().naturalVideoHeight > 0);
	    if(this.get_playState() == "Playing" && hasVideo) {
            this.get_element().content.findName("VideoThumbnail").visibility = "Collapsed";
        }
        else if(this.get_playState() == "Stopped") {
            this.get_element().content.findName("VideoThumbnail").visibility = "Visible";
        }
   },
   dispose:function() {
           delete this._stateChangedEventDelegate;
	       ExtendedPlayer.Player.callBaseMethod(this, 'dispose');
   }
}
ExtendedPlayer.Player.registerClass('ExtendedPlayer.Player', EePlayer.Player);

